Use case: ICACHE polling invalidate with error interrupt enabled

This use case shows how to run a polling invalidate operation while the ICACHE error interrupt is enabled, comparing HAL1 and HAL2.

Sequence diagram

    @startuml
    participant "User\nApplication" order 1
    participant "ICACHE\nDriver" order 2
    participant "ICACHE\nIRQHandler" order 3

    skinparam sequenceMessageAlign center

    group Option Register Error Callback
    "User\nApplication" ->"ICACHE\nDriver": HAL_ICACHE_RegisterErrorCallback(USER_ICACHE_ErrorCallback)
    "ICACHE\nDriver"-->"User\nApplication":HAL_OK
    end
    "User\nApplication"->"ICACHE\nDriver": HAL_ICACHE_Enable
    "User\nApplication"->"ICACHE\nDriver": __HAL_ICACHE_ENABLE_IT
    note right: ICACHE_IT_ERROR
    "ICACHE\nDriver"-->"User\nApplication":HAL_OK
    "User\nApplication" [#blue]->"ICACHE\nDriver": HAL_ICACHE_Invalidate
    activate "ICACHE\nDriver" #blue
    note over "ICACHE\nDriver":Check Busy flag : Flag = 0
    "ICACHE\nIRQHandler" <[#orange]-:ICACHE Error interrupt
    "ICACHE\nIRQHandler" -[#orange]> "ICACHE\nDriver" : HAL_ICACHE_IRQHandler
    activate "ICACHE\nDriver" #orange
    note over "ICACHE\nDriver":Flag Error Interrupt = 1

    "ICACHE\nDriver"-[#orange]>"User\nApplication":USER_ICACHE_ErrorCallback(HAL_ICACHE_ERROR_WRITE_INTRUSION)
    "User\nApplication" -[#orange]->"ICACHE\nDriver"

    deactivate "ICACHE\nDriver"
    "ICACHE\nDriver"-[#blue]->"User\nApplication":HAL_OK
    deactivate "ICACHE\nDriver"

    note over "User\nApplication":For other user application
    @enduml

Code snippet

HAL1

HAL2

/* Optional: register error callback */
(void)HAL_ICACHE_RegisterErrorCallback(USER_ICACHE_ErrorCallback);

/* Enable ICACHE and enable error interrupt */
HAL_ICACHE_Enable();
__HAL_ICACHE_ENABLE_IT(ICACHE_IT_ERROR);

/* Polling invalidate */
if (HAL_ICACHE_Invalidate() != HAL_OK)
{
  Error_Handler();
}

/* In ICACHE_IRQHandler(): */
/* HAL_ICACHE_IRQHandler(); */
/* Optional: register error callback */
(void)HAL_ICACHE_RegisterErrorCallback(&hicache1, myICACHE_ErrorCallback);

/* Start ICACHE with error interrupt enabled */
if (HAL_ICACHE_Start(&hicache1, HAL_ICACHE_IT_ERROR) != HAL_OK)
{
  Error_Handler();
}

/* Polling invalidate */
if (HAL_ICACHE_Invalidate(&hicache1) != HAL_OK)
{
  Error_Handler();
}

/* In ICACHE_IRQHandler(): */
/* HAL_ICACHE_IRQHandler(&hicache1); */

Key changes

  1. HAL2 enables error interrupt as part of the HAL_ICACHE_Start() configuration, instead of using __HAL_ICACHE_ENABLE_IT().

  2. HAL2 keeps the invalidate API but updates it to a handle-based signature.

  3. HAL2 supports optional callback registration (HAL_ICACHE_RegisterErrorCallback()) when enabled at compile time.